-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Upgrade to commons-fileupload 1.5 #30416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@topce Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@topce Thank you for signing the Contributor License Agreement! |
when PR spring-projects/spring-framework#30416 is accepted we can revert this change and update spring framework
This PR doesn't fix CVE-2023-24998 by itself, as upgrading merely exposes the new configuration option introduced in commons-fileupload. According to https://security.snyk.io/vuln/SNYK-JAVA-COMMONSFILEUPLOAD-3326457, the option must be manually set in order to avoid security issues. This PR effectively raises the commons-fileupload baseline to 1.5 as it relies on newly introduced API; as a result, I don't think we can apply this in a maintenance branch like 5.3.x. This support has been removed entirely in Spring Framework 6.0 (see #27423). I think the most viable options here would be:
|
Agree user still need to set new configuration option in order to avoid DoS |
Here not sure , I know that it is removed from 6.0 that why made PR for 5.3.x that is still supported. |
"I think the most viable options here would be: override the CommonsFileUploadSupport.newFileUpload method in a subclass and setting the option there Can you elaborate more here not sure that understand. |
@topce if we introduce this change, this makes commons-fileupload 1.5 a requirement for all applications. This means that an application upgrading from the current
As described in the reference documentation, you need to create a As for using the standard Servlet mechanism, this is described in the reference documentation - and is the preferred variant anyway. |
@bclozel thanks for explanation!
Understand but maybe here it is worth to do it because it allow them to address security issue potential DoS attack |
"As described in the reference documentation, you need to create a CommonsMultipartResolver. In this case, one could subclass CommonsMultipartResolver and override its newFileUpload method to set that setFileCountMax option." |
"As for using the standard Servlet mechanism, this is described in the reference documentation - and is the preferred variant anyway." |
@topce Yes, the |
@bclozel yes but even there you need to migrate commons-fileupload 1.5 if you want to address |
Merging this PR is not enough to secure applications out of the box as the library does not enforce any value by default. Developers will require to manually update their codebase for that. We will discuss this issue as a team and report back here. |
OK |
@bclozel // fix potential DoS attack
// https://security.snyk.io/vuln/SNYK-JAVA-COMMONSFILEUPLOAD-3326457?utm_medium=Partner&utm_source=RedHat&utm_campaign=Code-Ready-Analytics-2020&utm_content=vuln%2FSNYK-JAVA-COMMONSFILEUPLOAD-3326457
public class SafeCommonsMultipartResolver extends CommonsMultipartResolver {
private long fileCountMax;
public void setFileCountMax(final long fileCountMax) {
this.fileCountMax = fileCountMax;
}
@Override
protected FileUpload prepareFileUpload(@Nullable String encoding) {
FileUpload actualFileUpload = super.prepareFileUpload(encoding);
actualFileUpload.setFileCountMax(fileCountMax);
return actualFileUpload;
}
} finally I use new class SafeCommonsMultipartResolver instead CommonsMultipartResolver @Bean(name = "multipartResolver")
public MultipartResolver multipartResolver(EushareConfiguration esConfig) {
SafeCommonsMultipartResolver multipartResolver = new SafeCommonsMultipartResolver();
// prevent Dos attack
// we just upload one file
multipartResolver.setFileCountMax(1);
multipartResolver.setMaxUploadSize(esConfig.getMaxSizeAllowedInBytes());
multipartResolver.setMaxUploadSizePerFile(
esConfig.getMaxSizeAllowedInBytes());
return multipartResolver;
} |
@bclozel That was main motivation for this PR |
We have decided to keep things as is because there is a workaround for this problem (and manual configuration is required anyway). Also, this support has been removed in the next generation of Framework so this is the opportunity for 5.3.x users to migrate to the standard fileupload support. |
fix https://security.snyk.io/vuln/SNYK-JAVA-COMMONSFILEUPLOAD-3326457
potential DoS attack
upgrade commons-fileupload to latest version 1.5
add setFileCountMax
handle FileCountLimitExceededException
update test file
add @SuppressWarnings("deprecation") in CorutinesUtils.java order to build project